package com.example.printer2

import android.content.DialogInterface
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import com.example.printer2.databinding.ActivityLoginBinding
import com.example.printer2.po.entity.LoginInfo
import com.jaeger.library.StatusBarUtil

class LoginActivity : AppCompatActivity() {

    var loginInfo: LoginInfo = LoginInfo()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val loginBinding: ActivityLoginBinding =
            DataBindingUtil.setContentView(this, R.layout.activity_login)
        loginBinding.lifecycleOwner = this
        loginInfo = ViewModelProvider(
            this,
            ViewModelProvider.NewInstanceFactory()
        ).get(LoginInfo::class.java)
        loginBinding.userInfo = loginInfo
        StatusBarUtil.setColor(this, resources.getColor(R.color.white),1)
    }

    fun login(view: View) {
        val ACCOUNT = "123@qq.com";
        val PASSWORD = "123";
        if (loginInfo.account.get().equals(ACCOUNT) && loginInfo.password.get()
                .equals(PASSWORD)
        ) {
            var intent = Intent(this, PrinterActivity::class.java)
            startActivity(intent)
        } else {
            AlertDialog.Builder(this).setTitle("错误")
                .setMessage("用户名或密码错误")
                .setCancelable(false).setPositiveButton(
                    "确定",
                    DialogInterface.OnClickListener { dialog, which -> dialog.dismiss() }
                ).show();
        }

    }

    fun toRegister(view: android.view.View)
    {
        val intent:Intent=Intent(this,RegisterActivity::class.java);
        startActivity(intent);
    }
}